import axios from 'axios';
import qs from 'query-string';

export interface BannerId {
    id: number;
}

export interface BannerRecord {
    id: number;
    title: string;
    image: string;
    url: string;
    sort: number;
    status: number;
    create_time: string;
    update_time: string;
}

export interface BannerListRes {
    list: BannerRecord[];
    total: number;
}

export interface BannerModel {
    id: number;
    title: string;
    image: string;
    url: string;
    sort: number;
    status: number;
}

export interface BannerParams extends Partial<BannerRecord> {
    page: number;
    pageSize: number;
}

/**
 * 获取banner列表
 * @param params
 */
export function queryBannerList(params: BannerParams) {
    return axios.get<BannerListRes>('/admin/banner/index', {
        params,
        paramsSerializer: (obj) => {
            return qs.stringify(obj);
        },
    });
}

/**
 * 获取banner详情
 * @param params
 */
export function queryBannerOne(params: BannerId) {
    return axios.get<BannerRecord>('/admin/banner/detail', {
        params,
        paramsSerializer: (obj) => {
            return qs.stringify(obj);
        },
    });
}

/**
 * 提交banner表单（创建/更新）
 * @param data
 */
export function submitBannerForm(data: any) {
    return axios.post('/admin/banner/submit', data);
}

/**
 * 删除banner
 * @param id
 */
export function delBanner(id: number) {
    return axios.post('/admin/banner/delete', { id });
}
